import React from 'react'
import styles from './index.module.scss'
import Icon from '@/components/Icon'
import { useHistory } from 'react-router-dom'
import classnames from 'classnames'

export default function NavBar({ children, extra, onLeftClick,className }) {
    const history = useHistory()
    const back = () => {
		if(!onLeftClick) {
			history.go(-1)
		}else {
			onLeftClick()
		}
    }
	return (
		<div className={classnames(styles.root, className)}>
			<div className="left">
				<Icon type="iconfanhui" onClick={back}></Icon>
			</div>

			<div className="title">{children}</div>

			<div className="right">{extra}</div>
		</div>
	)
}

// 也可以这样获取到history,location,match对象, withRouter是一个高阶函数, 可以增强组件
// export default withRouter(NavBar)
